<?php


abstract class BaseMlmPipsRebate extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $rebate_id;


	
	protected $amount;


	
	protected $detail_link;


	
	protected $package_name;


	
	protected $pips_rebate;


	
	protected $dist_code;


	
	protected $fullname;


	
	protected $volume;


	
	protected $dist_id;


	
	protected $pips_date;


	
	protected $created_by;


	
	protected $created_on;


	
	protected $updated_by;


	
	protected $updated_on;

	
	protected $collMlmPipsRebateDetails;

	
	protected $lastMlmPipsRebateDetailCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getRebateId()
	{

		return $this->rebate_id;
	}

	
	public function getAmount()
	{

		return $this->amount;
	}

	
	public function getDetailLink()
	{

		return $this->detail_link;
	}

	
	public function getPackageName()
	{

		return $this->package_name;
	}

	
	public function getPipsRebate()
	{

		return $this->pips_rebate;
	}

	
	public function getDistCode()
	{

		return $this->dist_code;
	}

	
	public function getFullname()
	{

		return $this->fullname;
	}

	
	public function getVolume()
	{

		return $this->volume;
	}

	
	public function getDistId()
	{

		return $this->dist_id;
	}

	
	public function getPipsDate($format = 'Y-m-d H:i:s')
	{

		if ($this->pips_date === null || $this->pips_date === '') {
			return null;
		} elseif (!is_int($this->pips_date)) {
						$ts = strtotime($this->pips_date);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [pips_date] as date/time value: " . var_export($this->pips_date, true));
			}
		} else {
			$ts = $this->pips_date;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedBy()
	{

		return $this->created_by;
	}

	
	public function getCreatedOn($format = 'Y-m-d H:i:s')
	{

		if ($this->created_on === null || $this->created_on === '') {
			return null;
		} elseif (!is_int($this->created_on)) {
						$ts = strtotime($this->created_on);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_on] as date/time value: " . var_export($this->created_on, true));
			}
		} else {
			$ts = $this->created_on;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getUpdatedBy()
	{

		return $this->updated_by;
	}

	
	public function getUpdatedOn($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_on === null || $this->updated_on === '') {
			return null;
		} elseif (!is_int($this->updated_on)) {
						$ts = strtotime($this->updated_on);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_on] as date/time value: " . var_export($this->updated_on, true));
			}
		} else {
			$ts = $this->updated_on;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setRebateId($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->rebate_id !== $v) {
			$this->rebate_id = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::REBATE_ID;
		}

	} 

	
	public function setAmount($v)
	{

		if ($this->amount !== $v) {
			$this->amount = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::AMOUNT;
		}

	} 

	
	public function setDetailLink($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->detail_link !== $v) {
			$this->detail_link = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::DETAIL_LINK;
		}

	} 

	
	public function setPackageName($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->package_name !== $v) {
			$this->package_name = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::PACKAGE_NAME;
		}

	} 

	
	public function setPipsRebate($v)
	{

		if ($this->pips_rebate !== $v) {
			$this->pips_rebate = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::PIPS_REBATE;
		}

	} 

	
	public function setDistCode($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->dist_code !== $v) {
			$this->dist_code = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::DIST_CODE;
		}

	} 

	
	public function setFullname($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->fullname !== $v) {
			$this->fullname = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::FULLNAME;
		}

	} 

	
	public function setVolume($v)
	{

		if ($this->volume !== $v) {
			$this->volume = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::VOLUME;
		}

	} 

	
	public function setDistId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->dist_id !== $v) {
			$this->dist_id = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::DIST_ID;
		}

	} 

	
	public function setPipsDate($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [pips_date] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->pips_date !== $ts) {
			$this->pips_date = $ts;
			$this->modifiedColumns[] = MlmPipsRebatePeer::PIPS_DATE;
		}

	} 

	
	public function setCreatedBy($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->created_by !== $v) {
			$this->created_by = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::CREATED_BY;
		}

	} 

	
	public function setCreatedOn($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_on] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_on !== $ts) {
			$this->created_on = $ts;
			$this->modifiedColumns[] = MlmPipsRebatePeer::CREATED_ON;
		}

	} 

	
	public function setUpdatedBy($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->updated_by !== $v) {
			$this->updated_by = $v;
			$this->modifiedColumns[] = MlmPipsRebatePeer::UPDATED_BY;
		}

	} 

	
	public function setUpdatedOn($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_on] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_on !== $ts) {
			$this->updated_on = $ts;
			$this->modifiedColumns[] = MlmPipsRebatePeer::UPDATED_ON;
		}

	} 

	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->rebate_id = $rs->getString($startcol + 0);

			$this->amount = $rs->getFloat($startcol + 1);

			$this->detail_link = $rs->getString($startcol + 2);

			$this->package_name = $rs->getString($startcol + 3);

			$this->pips_rebate = $rs->getFloat($startcol + 4);

			$this->dist_code = $rs->getString($startcol + 5);

			$this->fullname = $rs->getString($startcol + 6);

			$this->volume = $rs->getFloat($startcol + 7);

			$this->dist_id = $rs->getInt($startcol + 8);

			$this->pips_date = $rs->getTimestamp($startcol + 9, null);

			$this->created_by = $rs->getInt($startcol + 10);

			$this->created_on = $rs->getTimestamp($startcol + 11, null);

			$this->updated_by = $rs->getInt($startcol + 12);

			$this->updated_on = $rs->getTimestamp($startcol + 13, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 14; 
		} catch (Exception $e) {
			throw new PropelException("Error populating MlmPipsRebate object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(MlmPipsRebatePeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			MlmPipsRebatePeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isNew() && !$this->isColumnModified(MlmPipsRebatePeer::CREATED_ON))
    {
      $this->setCreatedOn(time());
    }

    if ($this->isModified() && !$this->isColumnModified(MlmPipsRebatePeer::UPDATED_ON))
    {
      $this->setUpdatedOn(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(MlmPipsRebatePeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 
		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


			
			if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = MlmPipsRebatePeer::doInsert($this, $con);
					$affectedRows += 1; 
										 
										 

					$this->setRebateId($pk);  

					$this->setNew(false);
				} else {
					$affectedRows += MlmPipsRebatePeer::doUpdate($this, $con);
				}
				$this->resetModified(); 
			}

			if ($this->collMlmPipsRebateDetails !== null) {
				foreach($this->collMlmPipsRebateDetails as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 

	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = MlmPipsRebatePeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collMlmPipsRebateDetails !== null) {
					foreach($this->collMlmPipsRebateDetails as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = MlmPipsRebatePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getRebateId();
				break;
			case 1:
				return $this->getAmount();
				break;
			case 2:
				return $this->getDetailLink();
				break;
			case 3:
				return $this->getPackageName();
				break;
			case 4:
				return $this->getPipsRebate();
				break;
			case 5:
				return $this->getDistCode();
				break;
			case 6:
				return $this->getFullname();
				break;
			case 7:
				return $this->getVolume();
				break;
			case 8:
				return $this->getDistId();
				break;
			case 9:
				return $this->getPipsDate();
				break;
			case 10:
				return $this->getCreatedBy();
				break;
			case 11:
				return $this->getCreatedOn();
				break;
			case 12:
				return $this->getUpdatedBy();
				break;
			case 13:
				return $this->getUpdatedOn();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = MlmPipsRebatePeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getRebateId(),
			$keys[1] => $this->getAmount(),
			$keys[2] => $this->getDetailLink(),
			$keys[3] => $this->getPackageName(),
			$keys[4] => $this->getPipsRebate(),
			$keys[5] => $this->getDistCode(),
			$keys[6] => $this->getFullname(),
			$keys[7] => $this->getVolume(),
			$keys[8] => $this->getDistId(),
			$keys[9] => $this->getPipsDate(),
			$keys[10] => $this->getCreatedBy(),
			$keys[11] => $this->getCreatedOn(),
			$keys[12] => $this->getUpdatedBy(),
			$keys[13] => $this->getUpdatedOn(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = MlmPipsRebatePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setRebateId($value);
				break;
			case 1:
				$this->setAmount($value);
				break;
			case 2:
				$this->setDetailLink($value);
				break;
			case 3:
				$this->setPackageName($value);
				break;
			case 4:
				$this->setPipsRebate($value);
				break;
			case 5:
				$this->setDistCode($value);
				break;
			case 6:
				$this->setFullname($value);
				break;
			case 7:
				$this->setVolume($value);
				break;
			case 8:
				$this->setDistId($value);
				break;
			case 9:
				$this->setPipsDate($value);
				break;
			case 10:
				$this->setCreatedBy($value);
				break;
			case 11:
				$this->setCreatedOn($value);
				break;
			case 12:
				$this->setUpdatedBy($value);
				break;
			case 13:
				$this->setUpdatedOn($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = MlmPipsRebatePeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setRebateId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setAmount($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setDetailLink($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setPackageName($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setPipsRebate($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setDistCode($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setFullname($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setVolume($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setDistId($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setPipsDate($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setCreatedBy($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setCreatedOn($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setUpdatedBy($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setUpdatedOn($arr[$keys[13]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(MlmPipsRebatePeer::DATABASE_NAME);

		if ($this->isColumnModified(MlmPipsRebatePeer::REBATE_ID)) $criteria->add(MlmPipsRebatePeer::REBATE_ID, $this->rebate_id);
		if ($this->isColumnModified(MlmPipsRebatePeer::AMOUNT)) $criteria->add(MlmPipsRebatePeer::AMOUNT, $this->amount);
		if ($this->isColumnModified(MlmPipsRebatePeer::DETAIL_LINK)) $criteria->add(MlmPipsRebatePeer::DETAIL_LINK, $this->detail_link);
		if ($this->isColumnModified(MlmPipsRebatePeer::PACKAGE_NAME)) $criteria->add(MlmPipsRebatePeer::PACKAGE_NAME, $this->package_name);
		if ($this->isColumnModified(MlmPipsRebatePeer::PIPS_REBATE)) $criteria->add(MlmPipsRebatePeer::PIPS_REBATE, $this->pips_rebate);
		if ($this->isColumnModified(MlmPipsRebatePeer::DIST_CODE)) $criteria->add(MlmPipsRebatePeer::DIST_CODE, $this->dist_code);
		if ($this->isColumnModified(MlmPipsRebatePeer::FULLNAME)) $criteria->add(MlmPipsRebatePeer::FULLNAME, $this->fullname);
		if ($this->isColumnModified(MlmPipsRebatePeer::VOLUME)) $criteria->add(MlmPipsRebatePeer::VOLUME, $this->volume);
		if ($this->isColumnModified(MlmPipsRebatePeer::DIST_ID)) $criteria->add(MlmPipsRebatePeer::DIST_ID, $this->dist_id);
		if ($this->isColumnModified(MlmPipsRebatePeer::PIPS_DATE)) $criteria->add(MlmPipsRebatePeer::PIPS_DATE, $this->pips_date);
		if ($this->isColumnModified(MlmPipsRebatePeer::CREATED_BY)) $criteria->add(MlmPipsRebatePeer::CREATED_BY, $this->created_by);
		if ($this->isColumnModified(MlmPipsRebatePeer::CREATED_ON)) $criteria->add(MlmPipsRebatePeer::CREATED_ON, $this->created_on);
		if ($this->isColumnModified(MlmPipsRebatePeer::UPDATED_BY)) $criteria->add(MlmPipsRebatePeer::UPDATED_BY, $this->updated_by);
		if ($this->isColumnModified(MlmPipsRebatePeer::UPDATED_ON)) $criteria->add(MlmPipsRebatePeer::UPDATED_ON, $this->updated_on);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(MlmPipsRebatePeer::DATABASE_NAME);

		$criteria->add(MlmPipsRebatePeer::REBATE_ID, $this->rebate_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getRebateId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setRebateId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setAmount($this->amount);

		$copyObj->setDetailLink($this->detail_link);

		$copyObj->setPackageName($this->package_name);

		$copyObj->setPipsRebate($this->pips_rebate);

		$copyObj->setDistCode($this->dist_code);

		$copyObj->setFullname($this->fullname);

		$copyObj->setVolume($this->volume);

		$copyObj->setDistId($this->dist_id);

		$copyObj->setPipsDate($this->pips_date);

		$copyObj->setCreatedBy($this->created_by);

		$copyObj->setCreatedOn($this->created_on);

		$copyObj->setUpdatedBy($this->updated_by);

		$copyObj->setUpdatedOn($this->updated_on);


		if ($deepCopy) {
			
			
			$copyObj->setNew(false);

			foreach($this->getMlmPipsRebateDetails() as $relObj) {
				$copyObj->addMlmPipsRebateDetail($relObj->copy($deepCopy));
			}

		} 


		$copyObj->setNew(true);

		$copyObj->setRebateId(NULL); 

	}

	
	public function copy($deepCopy = false)
	{
		
		$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new MlmPipsRebatePeer();
		}
		return self::$peer;
	}

	
	public function initMlmPipsRebateDetails()
	{
		if ($this->collMlmPipsRebateDetails === null) {
			$this->collMlmPipsRebateDetails = array();
		}
	}

	
	public function getMlmPipsRebateDetails($criteria = null, $con = null)
	{
		
		include_once 'lib/model/om/BaseMlmPipsRebateDetailPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collMlmPipsRebateDetails === null) {
			if ($this->isNew()) {
			   $this->collMlmPipsRebateDetails = array();
			} else {

				$criteria->add(MlmPipsRebateDetailPeer::REBATE_ID, $this->getRebateId());

				MlmPipsRebateDetailPeer::addSelectColumns($criteria);
				$this->collMlmPipsRebateDetails = MlmPipsRebateDetailPeer::doSelect($criteria, $con);
			}
		} else {
			
			if (!$this->isNew()) {
				
				
				


				$criteria->add(MlmPipsRebateDetailPeer::REBATE_ID, $this->getRebateId());

				MlmPipsRebateDetailPeer::addSelectColumns($criteria);
				if (!isset($this->lastMlmPipsRebateDetailCriteria) || !$this->lastMlmPipsRebateDetailCriteria->equals($criteria)) {
					$this->collMlmPipsRebateDetails = MlmPipsRebateDetailPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastMlmPipsRebateDetailCriteria = $criteria;
		return $this->collMlmPipsRebateDetails;
	}

	
	public function countMlmPipsRebateDetails($criteria = null, $distinct = false, $con = null)
	{
		
		include_once 'lib/model/om/BaseMlmPipsRebateDetailPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(MlmPipsRebateDetailPeer::REBATE_ID, $this->getRebateId());

		return MlmPipsRebateDetailPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addMlmPipsRebateDetail(MlmPipsRebateDetail $l)
	{
		$this->collMlmPipsRebateDetails[] = $l;
		$l->setMlmPipsRebate($this);
	}

} 